//#include<iostream>
//#include<unistd.h>
//#include<sys/types.h>
//#include<stdlib.h>
//#include<cstdio>
//int g_val = 110;
//
//int main()
//{
//  pid_t id = vfork();
//  if(id==0)
//  {
//
//    printf("child:PID: %d,PPID: %d\n",getpid(),getppid());
//    g_val=200;
//    exit(0);
//  }
//
//  sleep(3);
//
//
//  printf("father:PID: %d,PPID: %d,g_val=%d\n",getpid(),getppid(),g_val);
//  return 0;
//}
//
#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
#include<malloc.h>
void *Routine(void* arg)
{
  char* msg = (char*) arg;
  int count=5;
  while(count--)
  {
    printf("I am %s, pid: %d,ppid: %d,tid: %lu\n",msg, getpid(),getppid(), pthread_self());
    sleep(1);
  }
  return (void*)(2022);

}

int main()
{
  pthread_t tid[5];
  int i=0;
  for(i=0;i<5;i++)
  {
    char* buffer = (char*)malloc(64);
    sprintf(buffer,"thred %d", i+1);
    pthread_create(&tid[i], NULL, Routine, buffer);
    printf("%s tid is %lu\n", buffer, tid[i]);
  }

  printf("I am main thread!!!,pid: %d,ppid: %d,tid: %lu\n",getpid(),getppid(),pthread_self()); 
  for(i=0;i<5;i++)
  {
    void* ret = NULL;
    pthread_join(tid[i],&ret);
    printf("thread %d[%lu]...quit, exitcode: %ld\n",i,tid[i],(long)ret);
  }

  return 0;
}
